package org.yong.springbootcmd.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class WsProtocol {

    private int m; // 模块
    private int b; // 业务
    private int e; // 错误码
    private String es; // 错误消息
    private Object d; // 数据

    public WsProtocol(int m, int b, Object d) {
        this(m, b, 0, null, d);
    }

    public WsProtocol(int m, int b, int e) {
        this(m, b, e, null, null);
    }

    public WsProtocol(int m, int b, String es) {
        this(m, b, -1, es, null);
    }

    public WsProtocol(int m, int b, int e, String es) {
        this(m, b, e, es, null);
    }

    //<editor-fold desc="无协议连接">
    public static WsProtocol cmd(int e, String es, Object d) {
        return new WsProtocol(0, 0, e, es, d);
    }

    public static WsProtocol cmd(int e, String es) {
        return cmd(e, es, null);
    }

    public static WsProtocol cmd(Object d) {
        return cmd(0, null, d);
    }
    //</editor-fold>

    public static WsProtocol notFound(WsProtocol wp) {
        WsProtocol ret = new WsProtocol();
        ret.m = wp.m;
        ret.b = wp.b;
        ret.e = -1;
        ret.es = "未找到合适的处理程序";
        return ret;
    }
}
